//
//  HMStatusViewModel.swift
//  WeiboTT
//
//  Created by 王嘉涛 on 2016/11/17.
//  Copyright © 2016年 王嘉涛. All rights reserved.
//

import UIKit

class HMStatusViewModel: NSObject {

    // 增加一个纯种的URL类型的属性--> 记录用户头像地址
    var iconURL : URL?
    
    var verifitedImage : UIImage?
    
    var mbRankImage : UIImage?
    
    var status : HMStatus? {
        didSet {
            // 一旦外界设置值,就应该到didSet中计算用户地址
            iconURL = URL(string: status?.user?.avatar_large ?? "")
            
            // 处理微博认证的图片
            self.dealWeiboVerifitedImage()
            self.dealMbrankImage()

        }
    }
    

    // 处理微博用户等级图片
    private func dealMbrankImage() {
        let mbrank = status?.user?.mbrank ?? 0
        if mbrank > 0 && mbrank < 7 {
            // 赋值
            mbRankImage = UIImage(named: "common_icon_membership_level\(mbrank)")
        }
    }
    
    // 处理数据相关的业务逻辑,处理微博日期,微博来源
    private func dealWeiboVerifitedImage() {
        // 微博认证的图片
        let type = status?.user?.verified_type ?? -1
        // 判断type
        switch  type{
        case 0:
            verifitedImage = #imageLiteral(resourceName: "avatar_vip")
        case 2,3,5:
            verifitedImage = #imageLiteral(resourceName: "avatar_enterprise_vip")
        case 220:
            verifitedImage = #imageLiteral(resourceName: "avatar_grassroot")
        default:
            verifitedImage = nil
        }
    }
}
